<?php

namespace Home\Model;

use Think\Model;

class AddressModel extends Model
{
    public function __construct()
    {
        parent::__construct('address');
    }


    /**
     * 读取地址列表
     *
     * @param
     * @return array 数组格式的返回结果
     */
    public function getAddressList($condition = array(), $fields = '*', $order = '', $limit = '', $pagesize = '', $num = '')
    {
        $address_list = $this->where($condition)->field($fields)->order($order)->limit($limit)->page($pagesize, $num)->select();
        if (empty($address_list)) return array();
        return $address_list;
    }


    /**
     * 取得单条地址信息
     * @param array $condition
     * @param string $order
     */
    public function getAddressInfo($condition, $fields = '*')
    {
        return $this->where($condition)->field($fields)->find();

    }


    /**
     * 取数量
     * @param unknown $condition
     */
    public function addressCount($condition = array())
    {
        return $this->where($condition)->count();
    }


    /**
     * 新增地址
     *
     * @param array $param 参数内容
     * @return bool 布尔类型的返回结果
     */
    public function addAddress($param)
    {
        return $this->add($param);
    }


    /**
     * 更新地址信息
     *
     * @param array $param 更新数据
     * @return bool 布尔类型的返回结果
     */
    public function editAddress($condition, $update)
    {
        return $this->where($condition)->save($update);
    }


    /**
     * 删除地址
     *
     * @param int $id 记录ID
     * @return bool 布尔类型的返回结果
     */
    public function delAddress($condition)
    {
        if (empty($condition)) {
            return false;
        }
        return $this->where($condition)->delete();
    }


}